package cn.edu.sdjzu.xg.eagle.controller;

import cn.edu.sdjzu.xg.eagle.entities.CommunityActivity;
import cn.edu.sdjzu.xg.eagle.service.impl.CommunityActivityImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("CommunityActivitys")
public class CommunityActivityController {

    @Autowired
    private CommunityActivityImpl communityActivityService;

    @PostMapping
    public String addCommunityActivity(@RequestBody CommunityActivity communityActivity) {
        try {
            return communityActivityService.addCommunityActivity(communityActivity);
        } catch (Exception e) {
            e.printStackTrace();
            return "添加失败: " + e.getMessage();
        }
    }

    @PutMapping
    public String updateCommunityActivity(@RequestBody CommunityActivity communityActivity) {
        try {
            return communityActivityService.updateCommunityActivity(communityActivity);
        } catch (Exception e) {
            e.printStackTrace();
            return "更新失败: " + e.getMessage();
        }
    }
    @DeleteMapping("/{activityID}")
    public String deleteCommunityActivity(@PathVariable String activityID) {
        try {
            return communityActivityService.deleteCommunityActivity(activityID);
        } catch (Exception e) {
            e.printStackTrace();
            return "删除失败: " + e.getMessage();
        }
    }

    @GetMapping("/{activityID}")
    public CommunityActivity getCommunityActivity(@PathVariable String activityID) {
        try {
            return communityActivityService.findCommunityActivityByActivityID(activityID);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @GetMapping
    public List<CommunityActivity> getAllCommunityActivitys() {
        try {
            return communityActivityService.findCommunityActivitys();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}